package cn.itcast.zuoyebang;

import androidx.appcompat.app.AppCompatActivity;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.coordinatorlayout.widget.CoordinatorLayout;

import android.content.Intent;
import android.os.Bundle;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;

public class SplashActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash);

        ConstraintLayout layout = findViewById(R.id.layout);
        AlphaAnimation alphaAnimation = new AlphaAnimation(0f,1f);//调整透明度的动画
        alphaAnimation.setDuration(1);//动画播放时间

        //动画监听事件
        alphaAnimation.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {

            }

            @Override
            public void onAnimationEnd(Animation animation) {
                jumpToMain();
            }//动画结束后跳转到MainActivity

            @Override
            public void onAnimationRepeat(Animation animation) {

            }
        });

        layout.startAnimation(alphaAnimation);

    }

    private void jumpToMain(){
        Intent intent = new Intent(this,MainActivity.class);
        startActivity(intent);
        finish();
    }
}